echo "创建虚拟机公共网络"

source /root/admin-openrc.sh && neutron net-create public --shared --provider:physical_network public --provider:network_type flat

neutron subnet-create public 10.12.16.0/24 --name public \
  --allocation-pool start=10.12.16.2,end=10.12.16.254 \
  --dns-nameserver 8.8.8.8 --gateway 10.12.16.1

neutron net-update public --router:external

echo "download image"
wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img

echo "upload image"
source /root/admin-openrc.sh && glance image-create --name "cirros" \
--file cirros-0.3.4-x86_64-disk.img \
--disk-format qcow2 --container-format bare \
--visibility public --progress

echo "允许 ICMP (ping)"
source /root/admin-openrc.sh && nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
echo "允许安全 shell (SSH) 的访问"
source /root/admin-openrc.sh && nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
